home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / info / lispref.info-16.z / lispref.info-16
Encoding:
GNU Info File  |  1998-05-21  |  50.0 KB  |  1,327 lines

  1. This is Info file ../../info/lispref.info, produced by Makeinfo version
  2. 1.68 from the input file lispref.texi.
  3.  
  4.    Edition History:
  5.  
  6.    GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
  7. Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
  8. Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
  9. XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
  10. GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
  11. Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
  12. Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
  13. Reference Manual (for 19.15 and 20.1, 20.2) v3.2, April, May 1997
  14.  
  15.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
  16. Foundation, Inc.  Copyright (C) 1994, 1995 Sun Microsystems, Inc.
  17. Copyright (C) 1995, 1996 Ben Wing.
  18.  
  19.    Permission is granted to make and distribute verbatim copies of this
  20. manual provided the copyright notice and this permission notice are
  21. preserved on all copies.
  22.  
  23.    Permission is granted to copy and distribute modified versions of
  24. this manual under the conditions for verbatim copying, provided that the
  25. entire resulting derived work is distributed under the terms of a
  26. permission notice identical to this one.
  27.  
  28.    Permission is granted to copy and distribute translations of this
  29. manual into another language, under the above conditions for modified
  30. versions, except that this permission notice may be stated in a
  31. translation approved by the Foundation.
  32.  
  33.    Permission is granted to copy and distribute modified versions of
  34. this manual under the conditions for verbatim copying, provided also
  35. that the section entitled "GNU General Public License" is included
  36. exactly as in the original, and provided that the entire resulting
  37. derived work is distributed under the terms of a permission notice
  38. identical to this one.
  39.  
  40.    Permission is granted to copy and distribute translations of this
  41. manual into another language, under the above conditions for modified
  42. versions, except that the section entitled "GNU General Public License"
  43. may be included in a translation approved by the Free Software
  44. Foundation instead of in the original English.
  45.  
  46. 
  47. File: lispref.info,  Node: Using Interactive,  Next: Interactive Codes,  Up: Defining Commands
  48.  
  49. Using `interactive'
  50. -------------------
  51.  
  52.    This section describes how to write the `interactive' form that
  53. makes a Lisp function an interactively-callable command.
  54.  
  55.  - Special Form: interactive ARG-DESCRIPTOR
  56.      This special form declares that the function in which it appears
  57.      is a command, and that it may therefore be called interactively
  58.      (via `M-x' or by entering a key sequence bound to it).  The
  59.      argument ARG-DESCRIPTOR declares how to compute the arguments to
  60.      the command when the command is called interactively.
  61.  
  62.      A command may be called from Lisp programs like any other
  63.      function, but then the caller supplies the arguments and
  64.      ARG-DESCRIPTOR has no effect.
  65.  
  66.      The `interactive' form has its effect because the command loop
  67.      (actually, its subroutine `call-interactively') scans through the
  68.      function definition looking for it, before calling the function.
  69.      Once the function is called, all its body forms including the
  70.      `interactive' form are executed, but at this time `interactive'
  71.      simply returns `nil' without even evaluating its argument.
  72.  
  73.    There are three possibilities for the argument ARG-DESCRIPTOR:
  74.  
  75.    * It may be omitted or `nil'; then the command is called with no
  76.      arguments.  This leads quickly to an error if the command requires
  77.      one or more arguments.
  78.  
  79.    * It may be a Lisp expression that is not a string; then it should
  80.      be a form that is evaluated to get a list of arguments to pass to
  81.      the command.
  82.  
  83.      If this expression reads keyboard input (this includes using the
  84.      minibuffer), keep in mind that the integer value of point or the
  85.      mark before reading input may be incorrect after reading input.
  86.      This is because the current buffer may be receiving subprocess
  87.      output; if subprocess output arrives while the command is waiting
  88.      for input, it could relocate point and the mark.
  89.  
  90.      Here's an example of what *not* to do:
  91.  
  92.           (interactive
  93.            (list (region-beginning) (region-end)
  94.                  (read-string "Foo: " nil 'my-history)))
  95.  
  96.      Here's how to avoid the problem, by examining point and the mark
  97.      only after reading the keyboard input:
  98.  
  99.           (interactive
  100.            (let ((string (read-string "Foo: " nil 'my-history)))
  101.              (list (region-beginning) (region-end) string)))
  102.  
  103.    * It may be a string; then its contents should consist of a code
  104.      character followed by a prompt (which some code characters use and
  105.      some ignore).  The prompt ends either with the end of the string
  106.      or with a newline.  Here is a simple example:
  107.  
  108.           (interactive "bFrobnicate buffer: ")
  109.  
  110.      The code letter `b' says to read the name of an existing buffer,
  111.      with completion.  The buffer name is the sole argument passed to
  112.      the command.  The rest of the string is a prompt.
  113.  
  114.      If there is a newline character in the string, it terminates the
  115.      prompt.  If the string does not end there, then the rest of the
  116.      string should contain another code character and prompt,
  117.      specifying another argument.  You can specify any number of
  118.      arguments in this way.
  119.  
  120.      The prompt string can use `%' to include previous argument values
  121.      (starting with the first argument) in the prompt.  This is done
  122.      using `format' (*note Formatting Strings::.).  For example, here
  123.      is how you could read the name of an existing buffer followed by a
  124.      new name to give to that buffer:
  125.  
  126.           (interactive "bBuffer to rename: \nsRename buffer %s to: ")
  127.  
  128.      If the first character in the string is `*', then an error is
  129.      signaled if the buffer is read-only.
  130.  
  131.      If the first character in the string is `@', and if the key
  132.      sequence used to invoke the command includes any mouse events, then
  133.      the window associated with the first of those events is selected
  134.      before the command is run.
  135.  
  136.      If the first character in the string is `_', then this command will
  137.      not cause the region to be deactivated when it completes; that is,
  138.      `zmacs-region-stays' will be set to `t' when the command exits
  139.      successfully.
  140.  
  141.      You can use `*', `@', and `_' together; the order does not matter.
  142.      Actual reading of arguments is controlled by the rest of the
  143.      prompt string (starting with the first character that is not `*',
  144.      `@', or `_').
  145.  
  146. 
  147. File: lispref.info,  Node: Interactive Codes,  Next: Interactive Examples,  Prev: Using Interactive,  Up: Defining Commands
  148.  
  149. Code Characters for `interactive'
  150. ---------------------------------
  151.  
  152.    The code character descriptions below contain a number of key words,
  153. defined here as follows:
  154.  
  155. Completion
  156.      Provide completion.  <TAB>, <SPC>, and <RET> perform name
  157.      completion because the argument is read using `completing-read'
  158.      (*note Completion::.).  `?' displays a list of possible
  159.      completions.
  160.  
  161. Existing
  162.      Require the name of an existing object.  An invalid name is not
  163.      accepted; the commands to exit the minibuffer do not exit if the
  164.      current input is not valid.
  165.  
  166. Default
  167.      A default value of some sort is used if the user enters no text in
  168.      the minibuffer.  The default depends on the code character.
  169.  
  170. No I/O
  171.      This code letter computes an argument without reading any input.
  172.      Therefore, it does not use a prompt string, and any prompt string
  173.      you supply is ignored.
  174.  
  175.      Even though the code letter doesn't use a prompt string, you must
  176.      follow it with a newline if it is not the last code character in
  177.      the string.
  178.  
  179. Prompt
  180.      A prompt immediately follows the code character.  The prompt ends
  181.      either with the end of the string or with a newline.
  182.  
  183. Special
  184.      This code character is meaningful only at the beginning of the
  185.      interactive string, and it does not look for a prompt or a newline.
  186.      It is a single, isolated character.
  187.  
  188.    Here are the code character descriptions for use with `interactive':
  189.  
  190. `*'
  191.      Signal an error if the current buffer is read-only.  Special.
  192.  
  193. `@'
  194.      Select the window mentioned in the first mouse event in the key
  195.      sequence that invoked this command.  Special.
  196.  
  197. `_'
  198.      Do not cause the region to be deactivated when this command
  199.      completes.  Special.
  200.  
  201. `a'
  202.      A function name (i.e., a symbol satisfying `fboundp').  Existing,
  203.      Completion, Prompt.
  204.  
  205. `b'
  206.      The name of an existing buffer.  By default, uses the name of the
  207.      current buffer (*note Buffers::.).  Existing, Completion, Default,
  208.      Prompt.
  209.  
  210. `B'
  211.      A buffer name.  The buffer need not exist.  By default, uses the
  212.      name of a recently used buffer other than the current buffer.
  213.      Completion, Default, Prompt.
  214.  
  215. `c'
  216.      A character.  The cursor does not move into the echo area.  Prompt.
  217.  
  218. `C'
  219.      A command name (i.e., a symbol satisfying `commandp').  Existing,
  220.      Completion, Prompt.
  221.  
  222. `d'
  223.      The position of point, as an integer (*note Point::.).  No I/O.
  224.  
  225. `D'
  226.      A directory name.  The default is the current default directory of
  227.      the current buffer, `default-directory' (*note System
  228.      Environment::.).  Existing, Completion, Default, Prompt.
  229.  
  230. `e'
  231.      The last mouse-button or misc-user event in the key sequence that
  232.      invoked the command.  No I/O.
  233.  
  234.      You can use `e' more than once in a single command's interactive
  235.      specification.  If the key sequence that invoked the command has N
  236.      mouse-button or misc-user events, the Nth `e' provides the Nth
  237.      such event.
  238.  
  239. `f'
  240.      A file name of an existing file (*note File Names::.).  The default
  241.      directory is `default-directory'.  Existing, Completion, Default,
  242.      Prompt.
  243.  
  244. `F'
  245.      A file name.  The file need not exist.  Completion, Default,
  246.      Prompt.
  247.  
  248. `k'
  249.      A key sequence (*note Keymap Terminology::.).  This keeps reading
  250.      events until a command (or undefined command) is found in the
  251.      current key maps.  The key sequence argument is represented as a
  252.      vector of events.  The cursor does not move into the echo area.
  253.      Prompt.
  254.  
  255.      This kind of input is used by commands such as `describe-key' and
  256.      `global-set-key'.
  257.  
  258. `K'
  259.      A key sequence, whose definition you intend to change.  This works
  260.      like `k', except that it suppresses, for the last input event in
  261.      the key sequence, the conversions that are normally used (when
  262.      necessary) to convert an undefined key into a defined one.
  263.  
  264. `m'
  265.      The position of the mark, as an integer.  No I/O.
  266.  
  267. `n'
  268.      A number read with the minibuffer.  If the input is not a number,
  269.      the user is asked to try again.  The prefix argument, if any, is
  270.      not used.  Prompt.
  271.  
  272. `N'
  273.      The raw prefix argument.  If the prefix argument is `nil', then
  274.      read a number as with `n'.  Requires a number.  *Note Prefix
  275.      Command Arguments::.  Prompt.
  276.  
  277. `p'
  278.      The numeric prefix argument.  (Note that this `p' is lower case.)
  279.      No I/O.
  280.  
  281. `P'
  282.      The raw prefix argument.  (Note that this `P' is upper case.)  No
  283.      I/O.
  284.  
  285. `r'
  286.      Point and the mark, as two numeric arguments, smallest first.
  287.      This is the only code letter that specifies two successive
  288.      arguments rather than one.  No I/O.
  289.  
  290. `s'
  291.      Arbitrary text, read in the minibuffer and returned as a string
  292.      (*note Text from Minibuffer::.).  Terminate the input with either
  293.      <LFD> or <RET>.  (`C-q' may be used to include either of these
  294.      characters in the input.)  Prompt.
  295.  
  296. `S'
  297.      An interned symbol whose name is read in the minibuffer.  Any
  298.      whitespace character terminates the input.  (Use `C-q' to include
  299.      whitespace in the string.)  Other characters that normally
  300.      terminate a symbol (e.g., parentheses and brackets) do not do so
  301.      here.  Prompt.
  302.  
  303. `v'
  304.      A variable declared to be a user option (i.e., satisfying the
  305.      predicate `user-variable-p').  *Note High-Level Completion::.
  306.      Existing, Completion, Prompt.
  307.  
  308. `x'
  309.      A Lisp object, specified with its read syntax, terminated with a
  310.      <LFD> or <RET>.  The object is not evaluated.  *Note Object from
  311.      Minibuffer::.  Prompt.
  312.  
  313. `X'
  314.      A Lisp form is read as with `x', but then evaluated so that its
  315.      value becomes the argument for the command.  Prompt.
  316.  
  317. 
  318. File: lispref.info,  Node: Interactive Examples,  Prev: Interactive Codes,  Up: Defining Commands
  319.  
  320. Examples of Using `interactive'
  321. -------------------------------
  322.  
  323.    Here are some examples of `interactive':
  324.  
  325.      (defun foo1 ()              ; `foo1' takes no arguments,
  326.          (interactive)           ;   just moves forward two words.
  327.          (forward-word 2))
  328.           => foo1
  329.      
  330.      (defun foo2 (n)             ; `foo2' takes one argument,
  331.          (interactive "p")       ;   which is the numeric prefix.
  332.          (forward-word (* 2 n)))
  333.           => foo2
  334.      
  335.      (defun foo3 (n)             ; `foo3' takes one argument,
  336.          (interactive "nCount:") ;   which is read with the Minibuffer.
  337.          (forward-word (* 2 n)))
  338.           => foo3
  339.      
  340.      (defun three-b (b1 b2 b3)
  341.        "Select three existing buffers.
  342.      Put them into three windows, selecting the last one."
  343.          (interactive "bBuffer1:\nbBuffer2:\nbBuffer3:")
  344.          (delete-other-windows)
  345.          (split-window (selected-window) 8)
  346.          (switch-to-buffer b1)
  347.          (other-window 1)
  348.          (split-window (selected-window) 8)
  349.          (switch-to-buffer b2)
  350.          (other-window 1)
  351.          (switch-to-buffer b3))
  352.           => three-b
  353.      (three-b "*scratch*" "declarations.texi" "*mail*")
  354.           => nil
  355.  
  356. 
  357. File: lispref.info,  Node: Interactive Call,  Next: Command Loop Info,  Prev: Defining Commands,  Up: Command Loop
  358.  
  359. Interactive Call
  360. ================
  361.  
  362.    After the command loop has translated a key sequence into a
  363. definition, it invokes that definition using the function
  364. `command-execute'.  If the definition is a function that is a command,
  365. `command-execute' calls `call-interactively', which reads the arguments
  366. and calls the command.  You can also call these functions yourself.
  367.  
  368.  - Function: commandp OBJECT
  369.      Returns `t' if OBJECT is suitable for calling interactively; that
  370.      is, if OBJECT is a command.  Otherwise, returns `nil'.
  371.  
  372.      The interactively callable objects include strings and vectors
  373.      (treated as keyboard macros), lambda expressions that contain a
  374.      top-level call to `interactive', compiled-function objects made
  375.      from such lambda expressions, autoload objects that are declared
  376.      as interactive (non-`nil' fourth argument to `autoload'), and some
  377.      of the primitive functions.
  378.  
  379.      A symbol is `commandp' if its function definition is `commandp'.
  380.  
  381.      Keys and keymaps are not commands.  Rather, they are used to look
  382.      up commands (*note Keymaps::.).
  383.  
  384.      See `documentation' in *Note Accessing Documentation::, for a
  385.      realistic example of using `commandp'.
  386.  
  387.  - Function: call-interactively COMMAND &optional RECORD-FLAG
  388.      This function calls the interactively callable function COMMAND,
  389.      reading arguments according to its interactive calling
  390.      specifications.  An error is signaled if COMMAND is not a function
  391.      or if it cannot be called interactively (i.e., is not a command).
  392.      Note that keyboard macros (strings and vectors) are not accepted,
  393.      even though they are considered commands, because they are not
  394.      functions.
  395.  
  396.      If RECORD-FLAG is the symbol `lambda', the interactive calling
  397.      arguments for `command' are read and returned as a list, but the
  398.      function is not called on them.
  399.  
  400.      If RECORD-FLAG is `t', then this command and its arguments are
  401.      unconditionally added to the list `command-history'.  Otherwise,
  402.      the command is added only if it uses the minibuffer to read an
  403.      argument.  *Note Command History::.
  404.  
  405.  - Function: command-execute COMMAND &optional RECORD-FLAG
  406.      This function executes COMMAND as an editing command.  The
  407.      argument COMMAND must satisfy the `commandp' predicate; i.e., it
  408.      must be an interactively callable function or a keyboard macro.
  409.  
  410.      A string or vector as COMMAND is executed with
  411.      `execute-kbd-macro'.  A function is passed to
  412.      `call-interactively', along with the optional RECORD-FLAG.
  413.  
  414.      A symbol is handled by using its function definition in its place.
  415.      A symbol with an `autoload' definition counts as a command if it
  416.      was declared to stand for an interactively callable function.
  417.      Such a definition is handled by loading the specified library and
  418.      then rechecking the definition of the symbol.
  419.  
  420.  - Command: execute-extended-command PREFIX-ARGUMENT
  421.      This function reads a command name from the minibuffer using
  422.      `completing-read' (*note Completion::.).  Then it uses
  423.      `command-execute' to call the specified command.  Whatever that
  424.      command returns becomes the value of `execute-extended-command'.
  425.  
  426.      If the command asks for a prefix argument, it receives the value
  427.      PREFIX-ARGUMENT.  If `execute-extended-command' is called
  428.      interactively, the current raw prefix argument is used for
  429.      PREFIX-ARGUMENT, and thus passed on to whatever command is run.
  430.  
  431.      `execute-extended-command' is the normal definition of `M-x', so
  432.      it uses the string `M-x ' as a prompt.  (It would be better to
  433.      take the prompt from the events used to invoke
  434.      `execute-extended-command', but that is painful to implement.)  A
  435.      description of the value of the prefix argument, if any, also
  436.      becomes part of the prompt.
  437.  
  438.           (execute-extended-command 1)
  439.           ---------- Buffer: Minibuffer ----------
  440.           1 M-x forward-word RET
  441.           ---------- Buffer: Minibuffer ----------
  442.                => t
  443.  
  444.  - Function: interactive-p
  445.      This function returns `t' if the containing function (the one that
  446.      called `interactive-p') was called interactively, with the function
  447.      `call-interactively'.  (It makes no difference whether
  448.      `call-interactively' was called from Lisp or directly from the
  449.      editor command loop.)  If the containing function was called by
  450.      Lisp evaluation (or with `apply' or `funcall'), then it was not
  451.      called interactively.
  452.  
  453.      The most common use of `interactive-p' is for deciding whether to
  454.      print an informative message.  As a special exception,
  455.      `interactive-p' returns `nil' whenever a keyboard macro is being
  456.      run.  This is to suppress the informative messages and speed
  457.      execution of the macro.
  458.  
  459.      For example:
  460.  
  461.           (defun foo ()
  462.             (interactive)
  463.             (and (interactive-p)
  464.                  (message "foo")))
  465.                => foo
  466.           
  467.           (defun bar ()
  468.             (interactive)
  469.             (setq foobar (list (foo) (interactive-p))))
  470.                => bar
  471.           
  472.           ;; Type `M-x foo'.
  473.                -| foo
  474.           
  475.           ;; Type `M-x bar'.
  476.           ;; This does not print anything.
  477.           
  478.           foobar
  479.                => (nil t)
  480.  
  481. 
  482. File: lispref.info,  Node: Command Loop Info,  Next: Events,  Prev: Interactive Call,  Up: Command Loop
  483.  
  484. Information from the Command Loop
  485. =================================
  486.  
  487.    The editor command loop sets several Lisp variables to keep status
  488. records for itself and for commands that are run.
  489.  
  490.  - Variable: last-command
  491.      This variable records the name of the previous command executed by
  492.      the command loop (the one before the current command).  Normally
  493.      the value is a symbol with a function definition, but this is not
  494.      guaranteed.
  495.  
  496.      The value is copied from `this-command' when a command returns to
  497.      the command loop, except when the command specifies a prefix
  498.      argument for the following command.
  499.  
  500.  - Variable: this-command
  501.      This variable records the name of the command now being executed by
  502.      the editor command loop.  Like `last-command', it is normally a
  503.      symbol with a function definition.
  504.  
  505.      The command loop sets this variable just before running a command,
  506.      and copies its value into `last-command' when the command finishes
  507.      (unless the command specifies a prefix argument for the following
  508.      command).
  509.  
  510.      Some commands set this variable during their execution, as a flag
  511.      for whatever command runs next.  In particular, the functions for
  512.      killing text set `this-command' to `kill-region' so that any kill
  513.      commands immediately following will know to append the killed text
  514.      to the previous kill.
  515.  
  516.    If you do not want a particular command to be recognized as the
  517. previous command in the case where it got an error, you must code that
  518. command to prevent this.  One way is to set `this-command' to `t' at the
  519. beginning of the command, and set `this-command' back to its proper
  520. value at the end, like this:
  521.  
  522.      (defun foo (args...)
  523.        (interactive ...)
  524.        (let ((old-this-command this-command))
  525.          (setq this-command t)
  526.          ...do the work...
  527.          (setq this-command old-this-command)))
  528.  
  529.  - Function: this-command-keys
  530.      This function returns a vector containing the key and mouse events
  531.      that invoked the present command, plus any previous commands that
  532.      generated the prefix argument for this command. (Note: this is not
  533.      the same as in FSF Emacs, which can return a string.)  *Note
  534.      Events::.
  535.  
  536.      This function copies the vector and the events; it is safe to keep
  537.      and modify them.
  538.  
  539.           (this-command-keys)
  540.           ;; Now use `C-u C-x C-e' to evaluate that.
  541.                => [#<keypress-event control-U> #<keypress-event control-X> #<keypress-event control-E>]
  542.  
  543.  - Variable: last-command-event
  544.      This variable is set to the last input event that was read by the
  545.      command loop as part of a command.  The principal use of this
  546.      variable is in `self-insert-command', which uses it to decide which
  547.      character to insert.
  548.  
  549.      This variable is off limits: you may not set its value or modify
  550.      the event that is its value, as it is destructively modified by
  551.      `read-key-sequence'.  If you want to keep a pointer to this value,
  552.      you must use `copy-event'.
  553.  
  554.      Note that this variable is an alias for `last-command-char' in FSF
  555.      Emacs.
  556.  
  557.           last-command-event
  558.           ;; Now type `C-u C-x C-e'.
  559.                => #<keypress-event control-E>
  560.  
  561.  - Variable: last-command-char
  562.      If the value of `last-command-event' is a keyboard event, then this
  563.      is the nearest character equivalent to it (or `nil' if there is no
  564.      character equivalent).  `last-command-char' is the character that
  565.      `self-insert-command' will insert in the buffer.  Remember that
  566.      there is *not* a one-to-one mapping between keyboard events and
  567.      XEmacs characters: many keyboard events have no corresponding
  568.      character, and when the Mule feature is available, most characters
  569.      can not be input on standard keyboards, except possibly with help
  570.      from an input method.  So writing code that examines this variable
  571.      to determine what key has been typed is bad practice, unless you
  572.      are certain that it will be one of a small set of characters.
  573.  
  574.      This variable exists for compatibility with Emacs version 18.
  575.  
  576.           last-command-char
  577.           ;; Now use `C-u C-x C-e' to evaluate that.
  578.                => ?\^E
  579.  
  580.  
  581.  - Variable: current-mouse-event
  582.      This variable holds the mouse-button event which invoked this
  583.      command, or `nil'.  This is what `(interactive "e")' returns.
  584.  
  585.  - Variable: echo-keystrokes
  586.      This variable determines how much time should elapse before command
  587.      characters echo.  Its value must be an integer, which specifies the
  588.      number of seconds to wait before echoing.  If the user types a
  589.      prefix key (say `C-x') and then delays this many seconds before
  590.      continuing, the key `C-x' is echoed in the echo area.  Any
  591.      subsequent characters in the same command will be echoed as well.
  592.  
  593.      If the value is zero, then command input is not echoed.
  594.  
  595. 
  596. File: lispref.info,  Node: Events,  Next: Reading Input,  Prev: Command Loop Info,  Up: Command Loop
  597.  
  598. Events
  599. ======
  600.  
  601.    The XEmacs command loop reads a sequence of "events" that represent
  602. keyboard or mouse activity.  Unlike in Emacs 18 and in FSF Emacs,
  603. events are a primitive Lisp type that must be manipulated using their
  604. own accessor and settor primitives.  This section describes the
  605. representation and meaning of input events in detail.
  606.  
  607.    A key sequence that starts with a mouse event is read using the
  608. keymaps of the buffer in the window that the mouse was in, not the
  609. current buffer.  This does not imply that clicking in a window selects
  610. that window or its buffer--that is entirely under the control of the
  611. command binding of the key sequence.
  612.  
  613.    For information about how exactly the XEmacs command loop works,
  614. *Note Reading Input::.
  615.  
  616.  - Function: eventp OBJECT
  617.      This function returns non-`nil' if EVENT is an input event.
  618.  
  619. * Menu:
  620.  
  621. * Event Types::            Events come in different types.
  622. * Event Contents::        What the contents of each event type are.
  623. * Event Predicates::        Querying whether an event is of a
  624.                   particular type.
  625. * Accessing Mouse Event Positions::
  626.                 Determining where a mouse event occurred,
  627.                   and over what.
  628. * Accessing Other Event Info::  Accessing non-positional event info.
  629. * Working With Events::        Creating, copying, and destroying events.
  630. * Converting Events::        Converting between events, keys, and
  631.                   characters.
  632.  
  633. 
  634. File: lispref.info,  Node: Event Types,  Next: Event Contents,  Up: Events
  635.  
  636. Event Types
  637. -----------
  638.  
  639.    Events represent keyboard or mouse activity or status changes of
  640. various sorts, such as process input being available or a timeout being
  641. triggered.  The different event types are as follows:
  642.  
  643. key-press event
  644.      A key was pressed.  Note that modifier keys such as "control",
  645.      "shift", and "alt" do not generate events; instead, they are
  646.      tracked internally by XEmacs, and non-modifier key presses
  647.      generate events that specify both the key pressed and the
  648.      modifiers that were held down at the time.
  649.  
  650. button-press event
  651. button-release event
  652.      A button was pressed or released.  Along with the button that was
  653.      pressed or released, button events specify the modifier keys that
  654.      were held down at the time and the position of the pointer at the
  655.      time.
  656.  
  657. dnd-drop event
  658.      Some dragged data was released. The event provides the button that
  659.      was used to drag the data, the modifier keys that were hold down,
  660.      the position where the drop took place, and a lisp object
  661.      containing the type and the data dropped (Note: until now only the
  662.      OffiX protocol supports dnd-drop).
  663.  
  664. motion event
  665.      The pointer was moved.  Along with the position of the pointer,
  666.      these events also specify the modifier keys that were held down at
  667.      the time.
  668.  
  669. misc-user event
  670.      A menu item was selected, or the scrollbar was used.
  671.  
  672. process event
  673.      Input is available on a process.
  674.  
  675. timeout event
  676.      A timeout has triggered.
  677.  
  678. magic event
  679.      Some window-system-specific action (such as a frame being resized
  680.      or a portion of a frame needing to be redrawn) has occurred.  The
  681.      contents of this event are not accessible at the E-Lisp level, but
  682.      `dispatch-event' knows what to do with an event of this type.
  683.  
  684. eval event
  685.      This is a special kind of event specifying that a particular
  686.      function needs to be called when this event is dispatched.  An
  687.      event of this type is sometimes placed in the event queue when a
  688.      magic event is processed.  This kind of event should generally
  689.      just be passed off to `dispatch-event'.  *Note Dispatching an
  690.      Event::.
  691.  
  692. 
  693. File: lispref.info,  Node: Event Contents,  Next: Event Predicates,  Prev: Event Types,  Up: Events
  694.  
  695. Contents of the Different Types of Events
  696. -----------------------------------------
  697.  
  698.    Every event, no matter what type it is, contains a timestamp (which
  699. is typically an offset in milliseconds from when the X server was
  700. started) indicating when the event occurred.  In addition, many events
  701. contain a "channel", which specifies which frame the event occurred on,
  702. and/or a value indicating which modifier keys (shift, control, etc.)
  703. were held down at the time of the event.
  704.  
  705.    The contents of each event are as follows:
  706.  
  707. key-press event
  708.  
  709.     channel
  710.  
  711.     timestamp
  712.  
  713.     key
  714.           Which key was pressed.  This is an integer (in the printing
  715.           ASCII range: >32 and <127) or a symbol such as `left' or
  716.           `right'.  Note that many physical keys are actually treated
  717.           as two separate keys, depending on whether the shift key is
  718.           pressed; for example, the "a" key is treated as either "a" or
  719.           "A" depending on the state of the shift key, and the "1" key
  720.           is similarly treated as either "1" or "!" on most keyboards.
  721.           In such cases, the shift key does not show up in the modifier
  722.           list.  For other keys, such as `backspace', the shift key
  723.           shows up as a regular modifier.
  724.  
  725.     modifiers
  726.           Which modifier keys were pressed.  As mentioned above, the
  727.           shift key is not treated as a modifier for many keys and will
  728.           not show up in this list in such cases.
  729.  
  730. button-press event
  731. button-release event
  732.  
  733.     channel
  734.  
  735.     timestamp
  736.  
  737.     button
  738.           What button went down or up.  Buttons are numbered starting
  739.           at 1.
  740.  
  741.     modifiers
  742.           Which modifier keys were pressed.  The special business
  743.           mentioned above for the shift key does *not* apply to mouse
  744.           events.
  745.  
  746.     x
  747.     y
  748.           The position of the pointer (in pixels) at the time of the
  749.           event.
  750.  
  751. dnd-drop event
  752.  
  753.     channel
  754.  
  755.     timestamp
  756.  
  757.     button
  758.           What button was used to drag. Buttons are numbered starting
  759.           at 1.
  760.  
  761.     modifiers
  762.           Which modifier keys were pressed to do the drag.
  763.  
  764.     x
  765.     y
  766.           The position of the pointer (in pixels) at the time of the
  767.           event.
  768.  
  769.     data
  770.           A lisp object containing the dropped type and data.
  771.  
  772. pointer-motion event
  773.  
  774.     channel
  775.  
  776.     timestamp
  777.  
  778.     x
  779.     y
  780.           The position of the pointer (in pixels) after it moved.
  781.  
  782.     modifiers
  783.           Which modifier keys were pressed.  The special business
  784.           mentioned above for the shift key does *not* apply to mouse
  785.           events.
  786.  
  787. misc-user event
  788.  
  789.     timestamp
  790.  
  791.     function
  792.           The E-Lisp function to call for this event.  This is normally
  793.           either `eval' or `call-interactively'.
  794.  
  795.     object
  796.           The object to pass to the function.  This is normally the
  797.           callback that was specified in the menu description.
  798.  
  799. process_event
  800.  
  801.     timestamp
  802.  
  803.     process
  804.           The Emacs "process" object in question.
  805.  
  806. timeout event
  807.  
  808.     timestamp
  809.  
  810.     function
  811.           The E-Lisp function to call for this timeout.  It is called
  812.           with one argument, the event.
  813.  
  814.     object
  815.           Some Lisp object associated with this timeout, to make it
  816.           easier to tell them apart.  The function and object for this
  817.           event were specified when the timeout was set.
  818.  
  819. magic event
  820.  
  821.     timestamp
  822.      (The rest of the information in this event is not user-accessible.)
  823.  
  824. eval event
  825.  
  826.     timestamp
  827.  
  828.     function
  829.           An E-Lisp function to call when this event is dispatched.
  830.  
  831.     object
  832.           The object to pass to the function.  The function and object
  833.           are set when the event is created.
  834.  
  835.  - Function: event-type EVENT
  836.      Return the type of EVENT.
  837.  
  838.      This will be a symbol; one of
  839.  
  840.     `key-press'
  841.           A key was pressed.
  842.  
  843.     `button-press'
  844.           A mouse button was pressed.
  845.  
  846.     `button-release'
  847.           A mouse button was released.
  848.  
  849.     `dnd-drop'
  850.           A drop occured.
  851.  
  852.     `motion'
  853.           The mouse moved.
  854.  
  855.     `misc-user'
  856.           Some other user action happened; typically, this is a menu
  857.           selection or scrollbar action.
  858.  
  859.     `process'
  860.           Input is available from a subprocess.
  861.  
  862.     `timeout'
  863.           A timeout has expired.
  864.  
  865.     `eval'
  866.           This causes a specified action to occur when dispatched.
  867.  
  868.     `magic'
  869.           Some window-system-specific event has occurred.
  870.  
  871. 
  872. File: lispref.info,  Node: Event Predicates,  Next: Accessing Mouse Event Positions,  Prev: Event Contents,  Up: Events
  873.  
  874. Event Predicates
  875. ----------------
  876.  
  877.    The following predicates return whether an object is an event of a
  878. particular type.
  879.  
  880.  - Function: key-press-event-p OBJECT
  881.      This is true if OBJECT is a key-press event.
  882.  
  883.  - Function: button-event-p OBJECT OBJECT
  884.      This is true if OBJECT is a mouse button-press or button-release
  885.      event.
  886.  
  887.  - Function: button-press-event-p OBJECT
  888.      This is true if OBJECT is a mouse button-press event.
  889.  
  890.  - Function: button-release-event-p OBJECT
  891.      This is true if OBJECT is a mouse button-release event.
  892.  
  893.  - Function: dnd-drop-event-p OBJECT
  894.      This is true if OBJECT is a mouse dnd-drop event.
  895.  
  896.  - Function: motion-event-p OBJECT
  897.      This is true if OBJECT is a mouse motion event.
  898.  
  899.  - Function: mouse-event-p OBJECT
  900.      This is true if OBJECT is a mouse button-press, button-release or
  901.      motion event.
  902.  
  903.  - Function: eval-event-p OBJECT
  904.      This is true if OBJECT is an eval event.
  905.  
  906.  - Function: misc-user-event-p OBJECT
  907.      This is true if OBJECT is a misc-user event.
  908.  
  909.  - Function: process-event-p OBJECT
  910.      This is true if OBJECT is a process event.
  911.  
  912.  - Function: timeout-event-p OBJECT
  913.      This is true if OBJECT is a timeout event.
  914.  
  915.  - Function: event-live-p OBJECT
  916.      This is true if OBJECT is any event that has not been deallocated.
  917.  
  918. 
  919. File: lispref.info,  Node: Accessing Mouse Event Positions,  Next: Accessing Other Event Info,  Prev: Event Predicates,  Up: Events
  920.  
  921. Accessing the Position of a Mouse Event
  922. ---------------------------------------
  923.  
  924.    Unlike other events, mouse events (i.e. motion, button-press,
  925. button-release, and dnd-drop events) occur in a particular location on
  926. the screen. Many primitives are provided for determining exactly where
  927. the event occurred and what is under that location.
  928.  
  929. * Menu:
  930.  
  931. * Frame-Level Event Position Info::
  932. * Window-Level Event Position Info::
  933. * Event Text Position Info::
  934. * Event Glyph Position Info::
  935. * Event Toolbar Position Info::
  936. * Other Event Position Info::
  937.  
  938. 
  939. File: lispref.info,  Node: Frame-Level Event Position Info,  Next: Window-Level Event Position Info,  Up: Accessing Mouse Event Positions
  940.  
  941. Frame-Level Event Position Info
  942. ...............................
  943.  
  944.    The following functions return frame-level information about where a
  945. mouse event occurred.
  946.  
  947.  - Function: event-frame EVENT
  948.      This function returns the "channel" or frame that the given mouse
  949.      motion, button press, button release, or dnd drop event occurred
  950.      in.  This will be `nil' for non-mouse events.
  951.  
  952.  - Function: event-x-pixel EVENT
  953.      This function returns the X position in pixels of the given mouse
  954.      event.  The value returned is relative to the frame the event
  955.      occurred in.  This will signal an error if the event is not a
  956.      mouse event.
  957.  
  958.  - Function: event-y-pixel EVENT
  959.      This function returns the Y position in pixels of the given mouse
  960.      event.  The value returned is relative to the frame the event
  961.      occurred in.  This will signal an error if the event is not a
  962.      mouse event.
  963.  
  964. 
  965. File: lispref.info,  Node: Window-Level Event Position Info,  Next: Event Text Position Info,  Prev: Frame-Level Event Position Info,  Up: Accessing Mouse Event Positions
  966.  
  967. Window-Level Event Position Info
  968. ................................
  969.  
  970.    The following functions return window-level information about where
  971. a mouse event occurred.
  972.  
  973.  - Function: event-window EVENT
  974.      Given a mouse motion, button press, button release, or dnd drop
  975.      event, compute and return the window on which that event occurred.
  976.      This may be `nil' if the event occurred in the border or over a
  977.      toolbar.  The modeline is considered to be within the window it
  978.      describes.
  979.  
  980.  - Function: event-buffer EVENT
  981.      Given a mouse motion, button press, button release, or dnd drop
  982.      event, compute and return the buffer of the window on which that
  983.      event occurred.  This may be `nil' if the event occurred in the
  984.      border or over a toolbar.  The modeline is considered to be within
  985.      the window it describes.  This is equivalent to calling
  986.      `event-window' and then calling `window-buffer' on the result if
  987.      it is a window.
  988.  
  989.  - Function: event-window-x-pixel EVENT
  990.      This function returns the X position in pixels of the given mouse
  991.      event.  The value returned is relative to the window the event
  992.      occurred in.  This will signal an error if the event is not a
  993.      mouse-motion, button-press, button-release, or dnd-drop event.
  994.  
  995.  - Function: event-window-y-pixel EVENT
  996.      This function returns the Y position in pixels of the given mouse
  997.      event.  The value returned is relative to the window the event
  998.      occurred in.  This will signal an error if the event is not a
  999.      mouse-motion, button-press, or button-release event.
  1000.  
  1001. 
  1002. File: lispref.info,  Node: Event Text Position Info,  Next: Event Glyph Position Info,  Prev: Window-Level Event Position Info,  Up: Accessing Mouse Event Positions
  1003.  
  1004. Event Text Position Info
  1005. ........................
  1006.  
  1007.    The following functions return information about the text (including
  1008. the modeline) that a mouse event occurred over or near.
  1009.  
  1010.  - Function: event-over-text-area-p EVENT
  1011.      Given a mouse-motion, button-press, button-release, or dnd-drop
  1012.      event, this function returns `t' if the event is over the text
  1013.      area of a window.  Otherwise, `nil' is returned.  The modeline is
  1014.      not considered to be part of the text area.
  1015.  
  1016.  - Function: event-over-modeline-p EVENT
  1017.      Given a mouse-motion, button-press, button-release, or dnd-drop
  1018.      event, this function returns `t' if the event is over the modeline
  1019.      of a window.  Otherwise, `nil' is returned.
  1020.  
  1021.  - Function: event-x EVENT
  1022.      This function returns the X position of the given mouse-motion,
  1023.      button-press, button-release, or dnd-drop event in characters.
  1024.      This is relative to the window the event occurred over.
  1025.  
  1026.  - Function: event-y EVENT
  1027.      This function returns the Y position of the given mouse-motion,
  1028.      button-press, button-release, or dnd-drop event in characters.
  1029.      This is relative to the window the event occurred over.
  1030.  
  1031.  - Function: event-point EVENT
  1032.      This function returns the character position of the given
  1033.      mouse-motion, button-press, button-release, or dnd-drop event.  If
  1034.      the event did not occur over a window, or did not occur over text,
  1035.      then this returns `nil'.  Otherwise, it returns an index into the
  1036.      buffer visible in the event's window.
  1037.  
  1038.  - Function: event-closest-point EVENT
  1039.      This function returns the character position of the given
  1040.      mouse-motion, button-press, button-release, or dnd-drop event.  If
  1041.      the event did not occur over a window or over text, it returns the
  1042.      closest point to the location of the event.  If the Y pixel
  1043.      position overlaps a window and the X pixel position is to the left
  1044.      of that window, the closest point is the beginning of the line
  1045.      containing the Y position.  If the Y pixel position overlaps a
  1046.      window and the X pixel position is to the right of that window,
  1047.      the closest point is the end of the line containing the Y
  1048.      position.  If the Y pixel position is above a window, 0 is
  1049.      returned.  If it is below a window, the value of `(window-end)' is
  1050.      returned.
  1051.  
  1052. 
  1053. File: lispref.info,  Node: Event Glyph Position Info,  Next: Event Toolbar Position Info,  Prev: Event Text Position Info,  Up: Accessing Mouse Event Positions
  1054.  
  1055. Event Glyph Position Info
  1056. .........................
  1057.  
  1058.    The following functions return information about the glyph (if any)
  1059. that a mouse event occurred over.
  1060.  
  1061.  - Function: event-over-glyph-p EVENT
  1062.      Given a mouse-motion, button-press, button-release, or dnd-drop
  1063.      event, this function returns `t' if the event is over a glyph.
  1064.      Otherwise, `nil' is returned.
  1065.  
  1066.  - Function: event-glyph-extent EVENT
  1067.      If the given mouse-motion, button-press, button-release, or
  1068.      dnd-drop event happened on top of a glyph, this returns its
  1069.      extent; else `nil' is returned.
  1070.  
  1071.  - Function: event-glyph-x-pixel EVENT
  1072.      Given a mouse-motion, button-press, button-release, or dnd-drop
  1073.      event over a glyph, this function returns the X position of the
  1074.      pointer relative to the upper left of the glyph.  If the event is
  1075.      not over a glyph, it returns `nil'.
  1076.  
  1077.  - Function: event-glyph-y-pixel EVENT
  1078.      Given a mouse-motion, button-press, button-release, or dnd-drop
  1079.      event over a glyph, this function returns the Y position of the
  1080.      pointer relative to the upper left of the glyph.  If the event is
  1081.      not over a glyph, it returns `nil'.
  1082.  
  1083. 
  1084. File: lispref.info,  Node: Event Toolbar Position Info,  Next: Other Event Position Info,  Prev: Event Glyph Position Info,  Up: Accessing Mouse Event Positions
  1085.  
  1086. Event Toolbar Position Info
  1087. ...........................
  1088.  
  1089.  - Function: event-over-toolbar-p EVENT
  1090.      Given a mouse-motion, button-press, button-release, or dnd-drop
  1091.      event, this function returns `t' if the event is over a toolbar.
  1092.      Otherwise, `nil' is returned.
  1093.  
  1094.  - Function: event-toolbar-button EVENT
  1095.      If the given mouse-motion, button-press, button-release, or
  1096.      dnd-drop event happened on top of a toolbar button, this function
  1097.      returns the button.  Otherwise, `nil' is returned.
  1098.  
  1099. 
  1100. File: lispref.info,  Node: Other Event Position Info,  Prev: Event Toolbar Position Info,  Up: Accessing Mouse Event Positions
  1101.  
  1102. Other Event Position Info
  1103. .........................
  1104.  
  1105.  - Function: event-over-border-p EVENT
  1106.      Given a mouse-motion, button-press, button-release, or dnd-drop
  1107.      event, this function returns `t' if the event is over an internal
  1108.      toolbar.  Otherwise, `nil' is returned.
  1109.  
  1110. 
  1111. File: lispref.info,  Node: Accessing Other Event Info,  Next: Working With Events,  Prev: Accessing Mouse Event Positions,  Up: Events
  1112.  
  1113. Accessing the Other Contents of Events
  1114. --------------------------------------
  1115.  
  1116.    The following functions allow access to the contents of events other
  1117. than the position info described in the previous section.
  1118.  
  1119.  - Function: event-timestamp EVENT
  1120.      This function returns the timestamp of the given event object.
  1121.  
  1122.  - Function: event-device EVENT
  1123.      This function returns the device that the given event occurred on.
  1124.  
  1125.  - Function: event-key EVENT
  1126.      This function returns the Keysym of the given key-press event.
  1127.      This will be the ASCII code of a printing character, or a symbol.
  1128.  
  1129.  - Function: event-button EVENT
  1130.      This function returns the button-number of the given button-press
  1131.      or button-release event.
  1132.  
  1133.  - Function: event-modifiers EVENT
  1134.      This function returns a list of symbols, the names of the modifier
  1135.      keys which were down when the given mouse or keyboard event was
  1136.      produced.
  1137.  
  1138.  - Function: event-modifier-bits EVENT
  1139.      This function returns a number representing the modifier keys
  1140.      which were down when the given mouse or keyboard event was
  1141.      produced.
  1142.  
  1143.  - Function: event-function EVENT
  1144.      This function returns the callback function of the given timeout,
  1145.      misc-user, or eval event.
  1146.  
  1147.  - Function: event-object EVENT
  1148.      This function returns the callback function argument of the given
  1149.      timeout, misc-user, or eval event.
  1150.  
  1151.  - Function: event-process EVENT
  1152.      This function returns the process of the given process event.
  1153.  
  1154.  - Function: event-drag-and-drop-data EVENT
  1155.      This function returns a list containing the type of the drop as
  1156.      first element and the data of the drop as second element.
  1157.  
  1158. 
  1159. File: lispref.info,  Node: Working With Events,  Next: Converting Events,  Prev: Accessing Other Event Info,  Up: Events
  1160.  
  1161. Working With Events
  1162. -------------------
  1163.  
  1164.    XEmacs provides primitives for creating, copying, and destroying
  1165. event objects.  Many functions that return events take an event object
  1166. as an argument and fill in the fields of this event; or they make accept
  1167. either an event object or `nil', creating the event object first in the
  1168. latter case.
  1169.  
  1170.  - Function: allocate-event
  1171.      This function returns an empty event structure.  WARNING: The event
  1172.      object returned may be a reused one; see the function
  1173.      `deallocate-event'.
  1174.  
  1175.  - Function: copy-event EVENT1 &optional EVENT2
  1176.      This function makes a copy of the given event object.  If a second
  1177.      argument is given, the first event is copied into the second and
  1178.      the second is returned.  If the second argument is not supplied
  1179.      (or is `nil') then a new event will be made as with
  1180.      `allocate-event'.
  1181.  
  1182.  - Function: deallocate-event EVENT
  1183.      This function allows the given event structure to be reused.  You
  1184.      *MUST NOT* use this event object after calling this function with
  1185.      it.  You will lose.  It is not necessary to call this function, as
  1186.      event objects are garbage-collected like all other objects;
  1187.      however, it may be more efficient to explicitly deallocate events
  1188.      when you are sure that that is safe.
  1189.  
  1190. 
  1191. File: lispref.info,  Node: Converting Events,  Prev: Working With Events,  Up: Events
  1192.  
  1193. Converting Events
  1194. -----------------
  1195.  
  1196.    XEmacs provides some auxiliary functions for converting between
  1197. events and other ways of representing keys.  These are useful when
  1198. working with ASCII strings and with keymaps.
  1199.  
  1200.  - Function: character-to-event CH &optional EVENT DEVICE
  1201.      This function converts a numeric ASCII value to an event structure,
  1202.      replete with modifier bits.  CH is the character to convert, and
  1203.      EVENT is the event object to fill in.  This function contains
  1204.      knowledge about what the codes "mean" - for example, the number 9
  1205.      is converted to the character <Tab>, not the distinct character
  1206.      <Control-I>.
  1207.  
  1208.      Note that CH does not have to be a numeric value, but can be a
  1209.      symbol such as `clear' or a list such as `(control backspace)'.
  1210.  
  1211.      If `event' is not `nil', it is modified; otherwise, a new event
  1212.      object is created.  In both cases, the event is returned.
  1213.  
  1214.      Optional third arg DEVICE is the device to store in the event;
  1215.      this also affects whether the high bit is interpreted as a meta
  1216.      key.  A value of `nil' means use the selected device but always
  1217.      treat the high bit as meta.
  1218.  
  1219.      Beware that `character-to-event' and `event-to-character' are not
  1220.      strictly inverse functions, since events contain much more
  1221.      information than the ASCII character set can encode.
  1222.  
  1223.  - Function: event-to-character EVENT &optional ALLOW-EXTRA-MODIFIERS
  1224.           ALLOW-META ALLOW-NON-ASCII
  1225.      This function returns the closest ASCII approximation to EVENT.
  1226.      If the event isn't a keypress, this returns `nil'.
  1227.  
  1228.      If ALLOW-EXTRA-MODIFIERS is non-`nil', then this is lenient in its
  1229.      translation; it will ignore modifier keys other than <control> and
  1230.      <meta>, and will ignore the <shift> modifier on those characters
  1231.      which have no shifted ASCII equivalent (<Control-Shift-A> for
  1232.      example, will be mapped to the same ASCII code as <Control-A>).
  1233.  
  1234.      If ALLOW-META is non-`nil', then the <Meta> modifier will be
  1235.      represented by turning on the high bit of the byte returned;
  1236.      otherwise, `nil' will be returned for events containing the <Meta>
  1237.      modifier.
  1238.  
  1239.      If ALLOW-NON-ASCII is non-`nil', then characters which are present
  1240.      in the prevailing character set (*note variable
  1241.      `character-set-property': Keymaps.) will be returned as their code
  1242.      in that character set, instead of the return value being
  1243.      restricted to ASCII.
  1244.  
  1245.      Note that specifying both ALLOW-META and ALLOW-NON-ASCII is
  1246.      ambiguous, as both use the high bit; <M-x> and <oslash> will be
  1247.      indistinguishable.
  1248.  
  1249.  - Function: events-to-keys EVENTS &optional NO-MICE
  1250.      Given a vector of event objects, this function returns a vector of
  1251.      key descriptors, or a string (if they all fit in the ASCII range).
  1252.      Optional arg NO-MICE means that button events are not allowed.
  1253.  
  1254. 
  1255. File: lispref.info,  Node: Reading Input,  Next: Waiting,  Prev: Events,  Up: Command Loop
  1256.  
  1257. Reading Input
  1258. =============
  1259.  
  1260.    The editor command loop reads keyboard input using the function
  1261. `next-event' and constructs key sequences out of the events using
  1262. `dispatch-event'.  Lisp programs can also use the function
  1263. `read-key-sequence', which reads input a key sequence at a time.  See
  1264. also `momentary-string-display' in *Note Temporary Displays::, and
  1265. `sit-for' in *Note Waiting::.  *Note Terminal Input::, for functions
  1266. and variables for controlling terminal input modes and debugging
  1267. terminal input.
  1268.  
  1269.    For higher-level input facilities, see *Note Minibuffers::.
  1270.  
  1271. * Menu:
  1272.  
  1273. * Key Sequence Input::        How to read one key sequence.
  1274. * Reading One Event::        How to read just one event.
  1275. * Dispatching an Event::        What to do with an event once it has been read.
  1276. * Quoted Character Input::    Asking the user to specify a character.
  1277. * Peeking and Discarding::        How to reread or throw away input events.
  1278.  
  1279. 
  1280. File: lispref.info,  Node: Key Sequence Input,  Next: Reading One Event,  Up: Reading Input
  1281.  
  1282. Key Sequence Input
  1283. ------------------
  1284.  
  1285.    Lisp programs can read input a key sequence at a time by calling
  1286. `read-key-sequence'; for example, `describe-key' uses it to read the
  1287. key to describe.
  1288.  
  1289.  - Function: read-key-sequence PROMPT
  1290.      This function reads a sequence of keystrokes or mouse clicks and
  1291.      returns it as a vector of events.  It keeps reading events until
  1292.      it has accumulated a full key sequence; that is, enough to specify
  1293.      a non-prefix command using the currently active keymaps.
  1294.  
  1295.      The vector and the event objects it contains are freshly created,
  1296.      and will not be side-effected by subsequent calls to this function.
  1297.  
  1298.      The function `read-key-sequence' suppresses quitting: `C-g' typed
  1299.      while reading with this function works like any other character,
  1300.      and does not set `quit-flag'.  *Note Quitting::.
  1301.  
  1302.      The argument PROMPT is either a string to be displayed in the echo
  1303.      area as a prompt, or `nil', meaning not to display a prompt.
  1304.  
  1305.      If the user selects a menu item while we are prompting for a key
  1306.      sequence, the returned value will be a vector of a single
  1307.      menu-selection event (a misc-user event).  An error will be
  1308.      signalled if you pass this value to `lookup-key' or a related
  1309.      function.
  1310.  
  1311.      In the example below, the prompt `?' is displayed in the echo area,
  1312.      and the user types `C-x C-f'.
  1313.  
  1314.           (read-key-sequence "?")
  1315.           
  1316.           ---------- Echo Area ----------
  1317.           ?C-x C-f
  1318.           ---------- Echo Area ----------
  1319.           
  1320.                => [#<keypress-event control-X> #<keypress-event control-F>]
  1321.  
  1322.    If an input character is an upper-case letter and has no key binding,
  1323. but its lower-case equivalent has one, then `read-key-sequence'
  1324. converts the character to lower case.  Note that `lookup-key' does not
  1325. perform case conversion in this way.
  1326.  
  1327.